﻿var Extension = {
    get: function (url, data, success) {
        $.ajax({
            type: 'POST',
            url: baseUrl + url,
            async: true,
            cache: false,
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                if (!!success && typeof success === 'function') {
                    success(data);
                }
            },
            error: function (xhr) {
                if (xhr.status === 409) {
                    //alert(xhr.responseText);
                }
            }
        });
    },
    post: function (url, data) {
        var result = null;

        $.ajax({
            type: 'POST',
            url: baseUrl + url,
            async: false,
            cache: false,
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                if (!!data) {
                    result = data;
                }
            },
            error: function (xhr) {
                if (xhr.status === 409) {
                    //alert(xhr.responseText);
                }
            }
        });

        return result;
    },
    crossDomainCall: function (url, data, success) {
        $.ajax({
            type: 'GET',
            url: url,
            async: true,
            cache: false,
            data: data,
            dataType: 'jsonp',
            crossDomain: true,
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                if (!!success && typeof success === 'function') {
                    success(data);
                }
            },
            error: function (xhr) {

            }
        });
    },
    getTemplate: function (url) {
        var result = null;
        $.ajax({
            type: 'GET',
            url: baseUrl + url,
            async: false,
            cache: false,
            success: function (data) {
                result = data;
            },
            error: function (xhr) {

            }
        });
        return result;
    }
};

var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

Date.prototype.toTwitterString = function () {
    return this.getHours().toString().padLeft('0', 2) + ':' + this.getMinutes().toString().padLeft('0', 2) + ' ' + this.getDate().toString().padLeft('0', 2) + ' ' + months[this.getMonth()] + ' ' + this.getFullYear();
};

String.prototype.padLeft = function (character, length) {
    var arr = [];
    while (length > 0) {
        arr.push(character);
        length--;
    }
    var str = "" + this;
    var pad = arr.join('');
    return pad.substring(0, pad.length - str.length) + str;
};